import 'package:look_net_ip_util/look_net_ip_utils.dart';
import 'package:test/test.dart';

import 'package:faker/faker.dart';

void main() {
  var ipUtils = IpUtils();
  group('ipv4MappedIpv6ToIpv4 tests', () {
    test('ipv4MappedIpv6ToIpv4 1', () {
      var ipv4MappedIpv6ToIpv4Default = ipUtils.ipv4MappedIpv6ToIpv4Default;
      var ip = "::ffff:192.168.1.1";
      // inputCaseMode
      var val = ipv4MappedIpv6ToIpv4Default(ip,
          inputMode: LeadingZerosMode.any,
          inputCaseMode: CaseMode.any,
          outputModeIpv4: LeadingZerosMode.any);
      expect(val, "192.168.1.1");
      val = ipv4MappedIpv6ToIpv4Default(ip,
          inputMode: LeadingZerosMode.any,
          inputCaseMode: CaseMode.lowercase,
          outputModeIpv4: LeadingZerosMode.any);
      expect(val, "192.168.1.1");
      val = ipv4MappedIpv6ToIpv4Default(ip,
          inputMode: LeadingZerosMode.any,
          inputCaseMode: CaseMode.uppercase,
          outputModeIpv4: LeadingZerosMode.any);
      expect(val, null);
      // inputMode
      val = ipv4MappedIpv6ToIpv4Default(ip,
          defaultValue: '',
          inputMode: LeadingZerosMode.included,
          inputCaseMode: CaseMode.any,
          outputModeIpv4: LeadingZerosMode.any);
      expect(val, '');
      val = ipv4MappedIpv6ToIpv4Default(ip,
          inputMode: LeadingZerosMode.includedCompletely,
          inputCaseMode: CaseMode.any,
          outputModeIpv4: LeadingZerosMode.any);
      expect(val, null);
      val = ipv4MappedIpv6ToIpv4Default(ip,
          inputMode: LeadingZerosMode.excluded,
          inputCaseMode: CaseMode.any,
          outputModeIpv4: LeadingZerosMode.any);
      expect(val, "192.168.1.1");
      // outputModeIpv4
      val = ipv4MappedIpv6ToIpv4Default(ip,
          defaultValue: '',
          inputMode: LeadingZerosMode.any,
          inputCaseMode: CaseMode.any,
          outputModeIpv4: LeadingZerosMode.any);
      expect(val, "192.168.1.1");
      val = ipv4MappedIpv6ToIpv4Default(ip,
          inputMode: LeadingZerosMode.any,
          inputCaseMode: CaseMode.any,
          outputModeIpv4: LeadingZerosMode.included);
      expect(val, "192.168.01.01");
      val = ipv4MappedIpv6ToIpv4Default(ip,
          inputMode: LeadingZerosMode.any,
          inputCaseMode: CaseMode.any,
          outputModeIpv4: LeadingZerosMode.includedCompletely);
      expect(val, "192.168.001.001");
    });
  });
  group('isIpv4MappedIpv6Normal tests', () {
    test('isIpv4MappedIpv6Normal 1', () {
      var isIpv4MappedIpv6Normal = ipUtils.isIpv4MappedIpv6Normal;
      var ip = "0:0:0:0:0:ffff:192.168.1.1";

      var val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.lowercase);
      expect(val, true);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.uppercase);
      expect(val, false);

      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.included, inputCaseMode: CaseMode.any);
      expect(val, false);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.includedCompletely,
          inputCaseMode: CaseMode.any);
      expect(val, false);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.excluded, inputCaseMode: CaseMode.any);
      expect(val, true);
    });

    test('isIpv4MappedIpv6Normal 2', () {
      var isIpv4MappedIpv6Normal = ipUtils.isIpv4MappedIpv6Normal;
      var ip = "00:000:0000:00:00:ffff:192.168.01.001";

      var val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.lowercase);
      expect(val, true);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.uppercase);
      expect(val, false);

      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.included, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.includedCompletely,
          inputCaseMode: CaseMode.any);
      expect(val, false);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.excluded, inputCaseMode: CaseMode.any);
      expect(val, false);
    });

    test('isIpv4MappedIpv6Normal 3', () {
      var isIpv4MappedIpv6Normal = ipUtils.isIpv4MappedIpv6Normal;
      var ip = "0000:0000:0000:0000:0000:FFFF:192.168.001.001";

      var val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.lowercase);
      expect(val, false);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.uppercase);
      expect(val, true);

      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.included, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.includedCompletely,
          inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Normal(ip,
          inputMode: LeadingZerosMode.excluded, inputCaseMode: CaseMode.any);
      expect(val, false);
    });
  });

  group('isIpv4MappedIpv6Compressed tests', () {
    var isIpv4MappedIpv6Compressed = ipUtils.isIpv4MappedIpv6Compressed;

    test('isIpv4MappedIpv6Compressed 1', () {
      var ip = "::ffff:192.168.1.2";

      var val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.lowercase);
      expect(val, true);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.uppercase);
      expect(val, false);

      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.included, inputCaseMode: CaseMode.any);
      expect(val, false);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.includedCompletely,
          inputCaseMode: CaseMode.any);
      expect(val, false);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.excluded, inputCaseMode: CaseMode.any);
      expect(val, true);
    });

    test('isIpv4MappedIpv6Compressed 2', () {
      var ip = "::FFFF:192.168.01.02";

      var val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.lowercase);
      expect(val, false);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.uppercase);
      expect(val, true);

      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.included, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.includedCompletely,
          inputCaseMode: CaseMode.any);
      expect(val, false);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.excluded, inputCaseMode: CaseMode.any);
      expect(val, false);
    });

    test('isIpv4MappedIpv6Compressed 3', () {
      var ip = "::FFFF:192.168.001.002";

      var val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.lowercase);
      expect(val, false);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.uppercase);
      expect(val, true);

      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.included, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.includedCompletely,
          inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv4MappedIpv6Compressed(ip,
          inputMode: LeadingZerosMode.excluded, inputCaseMode: CaseMode.any);
      expect(val, false);
    });
  });

  group('isIpv6Normal tests', () {
    test('isIpv6Normal 1', () {
      var isIpv6Normal = ipUtils.isIpv6Normal;

      var ip = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";

      var val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.lowercase);
      expect(val, true);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.uppercase);
      expect(val, false);

      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.included, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.includedCompletely,
          inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.excluded, inputCaseMode: CaseMode.any);
      expect(val, false);
    });

    test('isIpv6Normal 2', () {
      var isIpv6Normal = ipUtils.isIpv6Normal;
      var ip = "2001:db8:85a3:000:000:8a2e:370:7334";

      var val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.lowercase);
      expect(val, true);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.uppercase);
      expect(val, false);

      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.included, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.includedCompletely,
          inputCaseMode: CaseMode.any);
      expect(val, false);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.excluded, inputCaseMode: CaseMode.any);
      expect(val, false);
    });

    test('isIpv6Normal 3', () {
      var isIpv6Normal = ipUtils.isIpv6Normal;
      var ip = "2001:DB8:85A3:0:0:8A2E:370:7334";

      var val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.lowercase);
      expect(val, false);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.uppercase);
      expect(val, true);

      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.included, inputCaseMode: CaseMode.any);
      expect(val, false);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.includedCompletely,
          inputCaseMode: CaseMode.any);
      expect(val, false);
      val = isIpv6Normal(ip,
          inputMode: LeadingZerosMode.excluded, inputCaseMode: CaseMode.any);
      expect(val, true);
    });
  });

  group('isIpv6Compressed tests', () {
    test('isIpv6Compressed 1', () {
      var list = ipUtils.generateRandomIpv6List(BigInt.from(1000), false,
          outputMode: LeadingZerosMode.includedCompletely,
          outputCaseMode: CaseMode.uppercase,
          outputCompressed: true);

      for (var element in list) {
        print(element);
      }

      var isIpv6Compressed = ipUtils.isIpv6Compressed;

      var ip = "2001:0db8:85a3::8a2e:0370:7334";

      var val = isIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.lowercase);
      expect(val, true);
      val = isIpv6Compressed(ip,
          inputMode: LeadingZerosMode.any, inputCaseMode: CaseMode.uppercase);
      expect(val, false);

      val = isIpv6Compressed(ip,
          inputMode: LeadingZerosMode.included, inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv6Compressed(ip,
          inputMode: LeadingZerosMode.includedCompletely,
          inputCaseMode: CaseMode.any);
      expect(val, true);
      val = isIpv6Compressed(ip,
          inputMode: LeadingZerosMode.excluded, inputCaseMode: CaseMode.any);
      expect(val, false);
    });
  });
}
